package com.lottery.im.module.tim.model;

import android.text.TextUtils;
import com.tencent.imsdk.ext.group.TIMGroupPendencyHandledStatus;
import com.tencent.imsdk.ext.group.TIMGroupPendencyItem;

/**
 * 群关系链消息的界面绑定数据
 * 可用于本地操作后界面修改
 */
public class GroupFuture {

  private TIMGroupPendencyItem futureItem;

  private TIMGroupPendencyHandledStatus type;

  public GroupFuture(TIMGroupPendencyItem item) {
    futureItem = item;
    type = item.getHandledStatus();
  }

  public TIMGroupPendencyHandledStatus getType() {
    return type;
  }

  public void setType(TIMGroupPendencyHandledStatus type) {
    this.type = type;
  }

  public TIMGroupPendencyItem getFutureItem() {
    return futureItem;
  }

  public void setFutureItem(TIMGroupPendencyItem futureItem) {
    this.futureItem = futureItem;
  }

  private String mGroupName = "";
  private String mFromeUserName = "";
  private String mFromeUserAvatarUrl = "";
  private String mToUserName = "";

  /*
   * 群名字
   * */
  public String getGroupName() {
    String groupName = GroupInfo.getInstance().getGroupName(futureItem.getGroupId());
    if (!TextUtils.isEmpty(groupName)) {
      return groupName;
    }
    if (!TextUtils.isEmpty(mGroupName)) {
      return mGroupName;
    }
    return futureItem.getGroupId();
  }

  /*
   * 申请人名字
   * */
  public String getFromeUserName() {
    FriendProfile profile = FriendshipInfo.getInstance().getProfile(futureItem.getFromUser());
    if (null != profile && !TextUtils.isEmpty(profile.getName())) {
      return profile.getName();
    } else {
      return TextUtils.isEmpty(mFromeUserName) ? futureItem.getFromUser() : mFromeUserName;
    }
  }

  // 申请人 用户头像
  public String getAvatarUrl() {
    FriendProfile profile = FriendshipInfo.getInstance().getProfile(futureItem.getFromUser());

    if (null != profile && !TextUtils.isEmpty(profile.getAvatarUrl())) {
      return profile.getAvatarUrl();
    } else {
      return TextUtils.isEmpty(mFromeUserAvatarUrl) ? futureItem.getFromUser() : mFromeUserAvatarUrl;
    }
  }

  /*
   * 审核人名字
   * */
  public String getToUserName() {
    FriendProfile profile = FriendshipInfo.getInstance().getProfile(futureItem.getToUser());
    if (null != profile && !TextUtils.isEmpty(profile.getName())) {
      return profile.getName();
    } else {
      return TextUtils.isEmpty(mToUserName) ? futureItem.getToUser() : mToUserName;
    }
  }

  public void setGroupName(String groupName) {
    mGroupName = groupName;
  }

  public void setFromeUserName(String fromeUserName) {
    mFromeUserName = fromeUserName;
  }

  public void setFromeUserAvatarUrl(String fromeUserAvatarUrl) {
    mFromeUserAvatarUrl = fromeUserAvatarUrl;
  }

  public void setToUserName(String toUserName) {
    mToUserName = toUserName;
  }
}
